package us.ajg0702.leaderboards;

import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import us.ajg0702.leaderboards.cache.Cache;
import us.ajg0702.leaderboards.libs.spigot.Messages;
import us.ajg0702.leaderboards.signs.BoardSign;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;

public class Commands
        implements CommandExecutor, TabCompleter {
    Main pl;
    HashMap<CommandSender, String> confirmDeletes;

    public Commands(Main pl) {
        this.confirmDeletes = new HashMap<>();
        this.pl = pl;
    }

    public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
        String placeholder;
        boolean r;
        final String playername, board0, board1, boardn, list;
        int i;
        Player p;
        int pos;
        Block target;
        List<BoardSign> signs;
        String s;
        Player p1;
        Block target1;
        if (!sender.hasPermission("ajleaderboards.use")) {
            sender.sendMessage(color("&cYou do not have permission to use this!"));
            return true;
        }
        Player sply = (sender instanceof Player) ? (Player) sender : null;
        if (args.length == 0) {
            sender.sendMessage(color("&6ajLeaderboards v" + this.pl
                    " + label + " update & 7 - & eForces an update for a player\n & 7 See the wiki for more info."));


            return true;
        }
        final Cache cache = Cache.getInstance();
        switch (args[0].toLowerCase()) {
            case "add":
                if (args.length <= 1) {
                    " + label + " add<placeholder> "));
                    return true;
                }
                placeholder = args[1];
                placeholder = placeholder.replaceAll(Matcher.quoteReplacement("%"), "");
                if (!validatePlaceholder(placeholder, sply)) {
                    sender.sendMessage(color("&cThe placeholder '" + placeholder + "' does not give a numerical value. Make sure that the placeholder returns a number that is not formatted."));
                    return true;
                }
                r = cache.createBoard(placeholder);
                if (r) {
                    sender.sendMessage(color("&aBoard '" + placeholder + "' successfully created!"));
                } else {
                    sender.sendMessage(color("&cBoard '" + placeholder + "' creation failed! See console for more info."));
                }
                return true;
            case "reload":
                this.pl.config.reload();
                this.pl.msgs.reload();
                this.pl.reloadInterval();
                sender.sendMessage(color("&aConfig reloaded!"));
                return true;
            case "update":
                if (args.length <= 2) {
                    " + label + " update<board> <player > "));
                    return true;
                }
                Bukkit.getScheduler().runTaskAsynchronously(this.pl, new Runnable() {
                    public void run() {
                        String board = args[1];
                        if (!cache.getBoards().contains(board)) {
                            sender.sendMessage(Commands.this.color("&cThe board '" + board + "' does not exist."));

                            return;
                        }
                        OfflinePlayer p = Bukkit.getOfflinePlayer(args[2]);
                        cache.updateStat(args[1], p);
                        if (!p.isOnline()) {
                            sender.sendMessage(Commands.this.color("&6Warning: &7The player you requested to update appears to be offline. Not all placeholders support this. I'll still try, but if there is an error or nothing is updated, the placeholder probably doesn't support it."));
                        }
                        sender.sendMessage(Commands.this.color("&aAttempted to update stat for " + p.getName() + " on board " + args[1]));
                    }
                });
                return true;
            case "removeplayer":
                if (args.length <= 1) {
                    " + label + " removeplayer<player> <board > "));
                    return true;
                }
                if (args.length <= 2) {
                    " + label + " removeplayer<player> <board > "));
                    return true;
                }
                playername = args[1];
                board0 = args[2];
                if (!cache.getBoards().contains(board0)) {
                    sender.sendMessage(color("&cThe board '" + board0 + "' does not exist."));
                    return true;
                }
                Bukkit.getScheduler().runTaskAsynchronously(this.pl, () -> {
                    Cache.getInstance().removePlayer(board0, Bukkit.getOfflinePlayer(playername).getUniqueId());


                    sender.sendMessage(Messages.getInstance().color("&aRemoved " + playername + " from " + board0 + "!"));
                });


                " + label + " for help. ")); return true; }


                public List<String> onTabComplete (CommandSender sender, Command command, String label, String[]args){
                if (!sender.hasPermission("ajleaderboards.use")) {
                    return new ArrayList<>();
                }
                if (args.length <= 1)
                    return Arrays.asList(new String[]{"add", "list", "reload", "remove", "signs", "update", "removeplayer"});
                if (args.length == 2) {
                    switch (args[0]) {
                        case "update":
                        case "list":
                        case "remove":
                            return Cache.getInstance().getBoards();
                        case "signs":
                            return Arrays.asList(new String[]{"add", "list", "remove"});
                        case "removeplayer":
                            return null;
                    }
                    return new ArrayList<>();
                }
                if (args.length == 3) {
                    switch (args[0]) {
                        case "update":
                            return null;
                        case "signs":
                            switch (args[1]) {
                                case "add":
                                    return Cache.getInstance().getBoards();
                                case "list":
                                case "remove":
                                    return new ArrayList<>();
                            }
                        case "removeplayer":
                            return Cache.getInstance().getBoards();
                    }
                    return new ArrayList<>();
                }


                return new ArrayList<>();
            }


            public String color (String s){
                return ChatColor.translateAlternateColorCodes('&', s);
            }

            public boolean validatePlaceholder (String placeholder, Player sayOutput){
                if (Bukkit.getOnlinePlayers().size() == 0) {
                    this.pl.getLogger().warning("Unable to validate placeholder because no players are online.");
                    return true;
                }
                Player vp = Bukkit.getOnlinePlayers().iterator().next();
                String out = PlaceholderAPI.setPlaceholders(vp, "%" + Cache.alternatePlaceholders(placeholder) + "%").replaceAll(",", "");
                try {
                    Double.valueOf(out);
                } catch (NumberFormatException e) {
                    if (sayOutput != null) {
                        sayOutput.sendMessage(Messages.getInstance().color("&7Returned: " + out));
                    }
                    return false;
                }
                return true;
            }
        }


*Location:
        D:\User\Xuan\Downloads\ajLeaderboards - 1.3 .3.jar\\us\ajg0702\leaderboards\Commands.class
                * Java compiler version:8 (52.0)
                * JD - Core Version:
        1.1 .3
